package cdu.notFound.controller;
import cdu.notFound.model.Goods;
import cdu.notFound.service.GoodsService;
import cdu.notFound.service.impl.GoodsServiceImpl;
import cdu.notFound.utils.LoginVerify;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 物品审核
 */
@WebServlet("/AuditingServlet")
public class AuditingServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(LoginVerify.isAdmin(request)){
			int isPass=Integer.parseInt(request.getParameter("hd"));//1通过，0不通过
			int goodsId=Integer.parseInt(request.getParameter("goodsid"));
			boolean isSuc=false;
			GoodsService goodsService = new GoodsServiceImpl();
			Goods goods= goodsService.findById(goodsId);
			if(isPass==1){
				goods.setStates(2);
				isSuc=true;
			}else if(isPass==0){
				goods.setStates(3);
				isSuc=true;
			}else{
				response.getWriter().print("error");
			}
			if(isSuc){
				goodsService.doUpdate(goods);
				response.getWriter().print("success");
			}
		}else{
			response.getWriter().print("error");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}
